<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

class PublicAction extends Action {
	// 检查用户是否登录
/*	function index(){
		//重定向
		//echo PHP_FILE;
		redirect(PHP_FILE);		
		
	}*/
	
	Public function login() {
		if(!isset($_SESSION[C('USER_AUTH_KEY')])){
			$this->assign('sys_name',c('CMS_NAME'));
			$this->assign ("title", c('CMS_NAME'));
			$this->display();
		}
		
	}

	Public function checkuser(){
		//echo $_SESSION['verify']."<br>";
		//echo md5($_POST['verify'])."<br>";
		if($_SESSION['verify'] != md5($_POST['verify'])){
			//echo "3";
			$this->ajaxReturn(__APP__."/public/verify/",'验证码错误',0);
		}
		elseif(!$_POST['acc_name']){
			$this->error('用户名不能为空！');
		}
		else{
			
			//echo "1";
			//$a = $this->get();
			$map['acc_name'] = $_POST['acc_name'];
			$map['pwd'] = md5($_POST['pwd']);
			$user = D("member_info");
			$checkUser = $user->where($map)->find();
			
			//dump($checkUser);
			//echo MD5($pwd.$pwd_str)."<br>";
			//echo $log_chk['M_pwd'];
			if(!$checkUser){
				//$this->assign("jumpUrl","__APP__");
				$this->ajaxReturn(__ROOT__."/admin.php/public/verify/","用户名或密码不正确！",0);
			}else{
				$auth = d('role_info')->where('rid = '.$checkUser['rid'])->find();
				if($auth['admin']!="1"){
					$this->ajaxReturn(__ROOT__."/admin.php/public/verify/","没有管理员权限！",0);
				}
				else{
					Session::set(C('USER_AUTH_KEY'),$checkUser['uid']);
					Session::set('admin',$checkUser['acc_name']);
				//$Member->where("uid = ".$checkUser['uid'])->setField("lastlogintime",time());
				//echo$_SESSION['admin'];
				//$this->assign("jumpUrl","__ROOT__/Index");
				//$this->success("登陆成功！");
					$this->ajaxReturn(__ROOT__."/admin.php","登录成功",1);
				}
			}

		}
	}
	
	public function logout(){
		if(Session::is_set(C('USER_AUTH_KEY'))){
			//$_SESSION[C('USER_AUTH_KEY')] = "";
			unset($_SESSION[C('USER_AUTH_KEY')]);
			//session_destroy();
			//Session::clear();
			$this->assign('jumpUrl',__URL__.'/login');
			$this->success("注销成功！");
		}else{
			$this->assign('jumpUrl',__URL__.'/login');
			$this->error('已经注销！');
		}
		//$this->forward();
	}
	
	public function verify(){
		$type = isset($_GET['type'])?$_GET['type']:'gif'; 
		import("ORG.Util.Image");
	    Image::buildImageVerify(4,1,$type); 
    }
    
	public function top(){
		$this->display();
    }
	public function left(){
		$this->display();
    }
	public function main(){
		$this->display();
    }
    
    
}
?>